import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'name_bean.dart';
import 'package:heyangkuaidai/BussinessModule/ExpandGroupModule/groupseparate_title.dart';
class NameItemWidget extends StatefulWidget {

  final NameBean bean;
  final int index;
  NameItemWidget(this.bean,this.index);

  @override
  _NameItemWidgetState createState() => _NameItemWidgetState();
}

class _NameItemWidgetState extends State<NameItemWidget> {
  String _selectedTitle= " ";
  @override
  Widget build(BuildContext context) {
    return ListTile(
      title: _buildItem(widget.bean),
    );
  }

  Widget _buildItem(NameBean bean){
    if(bean.children.isEmpty){
      print(bean.name);
      return ListTile(
        title:Container(
          height: ScreenUtil().setWidth(99),
          width: ScreenUtil().setWidth(983),
          child:
          Column(
            children: [
              Container(width: ScreenUtil().setWidth(983),height: ScreenUtil().setWidth(1),color: Color(0xffE4E3E3),),
              SizedBox(height: ScreenUtil().setWidth(30),),
              Row(
                children: [
                  SizedBox(width: ScreenUtil().setWidth(93),),
                  Container(
                    width: ScreenUtil().setWidth(10),
                    height: ScreenUtil().setWidth(10),
                    decoration: ShapeDecoration(
                      color:_selectedTitle ==bean.name? Color(0xffF23C18):Color(0xffC2C2C2),
                      shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.all(
                          Radius.circular(5),
                        ),
                      ),
                    ),
                  ),

                  SizedBox(width: ScreenUtil().setWidth(19),),
                  Text(bean.name,style: TextStyle(fontFamily: "PingFangSC-Regular",fontSize: ScreenUtil().setSp(24),color:_selectedTitle ==bean.name? Color(0xffF23C18):Color(0xff333333)),),
                ],
              ) ,
            ],
          )
        ),
        onTap: (){
          setState(() {
            _selectedTitle =bean.name;
          });
        },
      );
    }
    return groupSeparateTitle(
      key: PageStorageKey<NameBean>(bean),
      title:Container(
          height: ScreenUtil().setWidth(99),
          // width: ScreenUtil().setWidth(100),
          child:Row(
          children: [
            bean.name.contains('公司')? SizedBox(width: ScreenUtil().setWidth(81),): SizedBox(width: ScreenUtil().setWidth(52),),
            Text(bean.name,style: TextStyle(fontFamily: "PingFangSC-Semibold",fontSize: ScreenUtil().setSp(24),color: Color(0xff333333)),),
            bean.name.contains('公司')?SizedBox(width: ScreenUtil().setWidth(52),):SizedBox(width: ScreenUtil().setWidth(81),)
          ],
        ),
      ),
      children: bean.children.map<Widget>(_buildItem).toList(),

    );
  }

}
